package com.ysh.smartplatform.controller;

import com.ysh.smartplatform.dto.R;
import com.ysh.smartplatform.pojo.Scene;
import com.ysh.smartplatform.service.SceneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 袁胜虎 on 2022/9/8 15:46
 */
@RestController
@RequestMapping("/secens")
@Api(tags = "场景管理模块")
public class SceneController {
    private SceneService sceneService;

    @Autowired
    public void setSceneService(SceneService sceneService) {
        this.sceneService = sceneService;
    }
    @PostMapping("/secen")
    @ApiOperation("添加场景")
    public R addScene(@RequestBody @Validated Scene scene){
        sceneService.addScene(scene);
        return R.OK();
    }
    @GetMapping("/secen/{sevenId}")
    @ApiOperation("根据id查询场景")
    public R findById(@PathVariable Long sevenId){
        return R.OK(sceneService.getSceneById(sevenId));
    }

    @GetMapping("/secens")
    public R findAllByUser() {
        return R.OK(sceneService.getAllScenesByUser());
    }

    @DeleteMapping("/secen/{sceneName}")
    @ApiOperation("根据场景名删除场景")
    public R deleteBySceneName(@PathVariable String sceneName){
        sceneService.deleteBySceneName(sceneName);
        return R.OK();
    }
//修改场景表
    @PostMapping("/secenUp")
    @ApiOperation("修改场景")
    public R updateScene(@RequestBody @Validated Scene scene){
        sceneService.updateScene(scene);
        return R.OK();
    }
}
